package main

import (
	"fmt"
	"regexp"
)

/**
获取城市名称和链接
(1) 使用css选择器
(2) 使用xpath
(3) 使用正则表达式
*/

const text1 = "My email is trt@mail.com"
const text2 = `
My email is trt@mail.com
email1 is abc@def.org
email2 is kkk@qq.com
`
const text3 = `
My email is trt@mail.com@abc.com
email1 is abc@def.org
email2 is    kkk@qq.com
email3 is ddd@abc.com.cn
`

func main() {
	method1()
	method2()
	method3()

}

func method1() {
	// re, err := regexp.Compile("trt@mail.com")
	re := regexp.MustCompile("trt@mail.com")
	match := re.FindString(text1)
	fmt.Println(match)
}

func method2() {
	re := regexp.MustCompile(`[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+`)
	match := re.FindAllString(text2, -1)
	fmt.Println(match)
}

func method3() {
	re := regexp.MustCompile(`([a-zA-Z0-9]+)@([a-zA-Z0-9]+)(\.[a-zA-Z0-9]+)`)
	match := re.FindAllStringSubmatch(text3, -1)
	for _, m := range match {
		fmt.Println(m)
	}
}
